package com.wanxi.education.controller.back;

import com.github.pagehelper.PageInfo;
import com.wanxi.education.common.CommonResult;
import com.wanxi.education.model.vo.order.OrderGoBackVo;
import com.wanxi.education.model.vo.order.OrderFuzzyQueryVo;
import com.wanxi.education.model.vo.order.OrderUpdateVo;
import com.wanxi.education.service.OrderBackService;
import io.swagger.annotations.*;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: 寇文宝
 * @Description:
 * @Date: Created in 2021/9/24
 * @Version: 1.0
 */
@Api(tags = "后台订单管理")
@RestController
@RequestMapping("/back/order")
public class OrderBackController {

    @Autowired
    private OrderBackService orderBackService;

    @ApiOperation("订单管理页面分页查询+模糊查询搜索订单列表")
    @PostMapping("/findPage")
    @ApiParam(name = "orderFuzzyQueryVo", value = "模糊查询vo类", required = true)
    public CommonResult findPage(@RequestBody OrderFuzzyQueryVo orderFuzzyQueryVo) {
        PageInfo<OrderGoBackVo> orderVoPageInfo = orderBackService.findPage(orderFuzzyQueryVo);
        return CommonResult.success(orderVoPageInfo);
    }

    @ApiOperation("订单管理页面查看订单状态")
    @GetMapping("/findById")
    @ApiParam(name = "id", value = "当前想要查看订单的id")
    public CommonResult findById(@RequestParam("id") Long id) {
        if (ObjectUtils.isEmpty(id)) {
            return CommonResult.validateFailed("订单id为空");
        }
        OrderUpdateVo orderUpdateVo = orderBackService.findById(id);
        return CommonResult.success(orderUpdateVo);
    }

    @ApiOperation("订单管理页面修改订单状态")
    @PostMapping("/update")
    @ApiParam(name = "orderUpdateVo", value = "修改视频vo类")
    public CommonResult update(@RequestBody OrderUpdateVo orderUpdateVo) {
        int update = orderBackService.update(orderUpdateVo);
        if (update == 1) {
            return CommonResult.success("修改成功");
        }
        return CommonResult.failure("修改失败");
    }
}
